﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="Change2.aspx.cs" Inherits="Ashlen.Portal.Web.Views.Account.Change" %>
<%@ Import Namespace="MvcContrib.UI.Html"%>


<asp:Content ContentPlaceHolderID="head" runat="server">
    <%= Html.Validation().ValidatorRegistrationScripts() %>
    <script type="text/javascript" src="../Content/MicrosoftAjax.js"></script>
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

    <script type="text/javascript">

        var ddlCountries;
        var ddlStates;

        function pageLoad() {
            ddlCountries = $get("country");
            ddlStates = $get("state");
            $addHandler(ddlCountries, "change", bindOptions);
            bindOptions();
        }

        function bindOptions() {
            ddlStates.options.length = 0;
            var countryId = ddlCountries.value;

            if (countryId) {
                var url = "../Account/GetStatesForCountry/" + countryId;
                getContent(url, bindOptionResults);
            }
        }

        function bindOptionResults(data) {
            var newOption;
            var found;
            found = false;
            for (var k = 0; k < data.length; k++) {
                newOption = new Option(data[k].Name, data[k].ID);
                
                if ($get("selectedState") != null) {
                    if (data[k].ID == $get("selectedState").value) {
                        newOption.selected = true;
                        found = true;
                    }
                }
                ddlStates.options.add(newOption);
            }
            if (found == false) {
                ddlStates.value = data[0].ID;
            }
        }

        /**** should be in library ***/
        function getContent(url, callback) {
            var request = new Sys.Net.WebRequest();
            request.set_url(url);
            request.set_httpVerb("GET");
            var del = Function.createCallback(getContentResults, callback);
            request.add_completed(del);
            request.invoke();
        }

        function getContentResults(executor, eventArgs, callback) {
            if (executor.get_responseAvailable()) {
                callback(eval("(" + executor.get_responseData() + ")"));
            }
            else {
                if (executor.get_timedOut())
                    alert("Timed Out");
                else if (executor.get_aborted())
                    alert("Aborted");
            }
        }

    </script>
    <h2>
        Account Update</h2>
    <p>
        Use the form below to create a update your account.
    </p>
    <p>
        Passwords are required to be a minimum of
        <%=Html.Encode(ViewData["PasswordLength"])%>
        characters in length.<br />
        Items marked with an asterisk (*) are mandatory.<br />
    </p>
    <%
        var errors = ViewData["errors"] as IList<string>;
        if (errors != null) {
    %>
    <ul class="error">
        <% foreach (string error in errors) { %>
        <li>
            <%= Html.Encode(error) %></li>
        <% } %>
    </ul>
    <%
        }
    %>
    <%= Html.Hidden("selectedState")%>"
    <% using (Html.Form("Account", "Update", FormMethod.Post, Html.Validation().FormValidation("regex"))) { %>
    <%--<form method="post" action="<%= Html.AttributeEncode(Url.Action("Update")) %>">--%>
    <div>
        <table>
            <tr>
                <td>
                    Username:
                </td>
                <td>
                    <%= ViewData["username"] %>
                </td>
            </tr>
            <tr>
                <td>
                    Email:
                </td>
                <td>
                    <%= Html.TextBox("email") %>*
                </td>
            </tr>
            <tr>
                <td>
                    Password:
                </td>                
                <td>
                    <%= Html.Password("password") %>
                </td>
            </tr>
            <tr>
                <td>
                    Confirm password:
                </td>
                <td>
                    <%= Html.Password("confirmPassword") %>
                    <%= Html.Validation().CompareValidator("compareValidator", "password", "confirmPassword", ValidationDataType.String, ValidationCompareOperator.Equal, "The password and confirmation do not match.", "compare")%>
                </td>
            </tr>
            <tr>
                <td>
                    Firstname:
                </td>
                <td>
                    
                    <%= Html.TextBox("firstName") %>*
                    <%= Html.Validation().RegularExpressionValidator("firstNameForRegexValidator", "firstName", "[a-zA-Z]*", "The name can only contain alpha characters.", "regex")%>                    
                </td>
            </tr>
            <tr>
                <td>
                    Lastname:
                </td>
                <td>
                    <%= Html.TextBox("lastName") %>*
                    <%= Html.Validation().RegularExpressionValidator("lastNameForRegexValidator", "lastName", "[a-zA-Z]*", "The name can only contain alpha characters.", "regex")%>
                </td>
            </tr>
            <tr>
                <td>
                    Nickname:
                </td>
                <td>
                    <%= Html.TextBox("nickName") %>
                </td>
            </tr>
            <tr>
                <td>
                    Date of Birth:
                </td>
                <td>
                    <%= Html.TextBox("dateOfBirth") %>
                                      
                </td>
            </tr>
            <tr>
                <td>
                    Sex:
                </td>
                <td>
                    <%= Html.DropDownList(string.Empty, "sex", new SelectList(new List<string> { "M", "F"})) %>*
                </td>
            </tr>
            <tr>
                <td>
                    Mobile:
                </td>
                <td>
                    <%= Html.TextBox("mobile")%>
                </td>
            </tr>
            <tr>
                <td>
                    Phone:
                </td>
                <td>
                    <%= Html.TextBox("phone")%>
                </td>
            </tr>
            <tr>
                <td>
                    Country:
                </td>
                <td>
                    <%= Html.DropDownList("", "country")%>*
                </td>
            </tr>
            <tr>
                <td>
                    State/Town:
                </td>
                <td>
                    <select id="state" name="state"></select>*
                </td>
            </tr>
            <tr>
                <td>
                    Postcode:
                </td>
                <td>
                    <%= Html.TextBox("postcode")%>
                </td>
            </tr>
            <tr>
                <td>
                    Send Me Community Alerts:
                </td>
                <td>
                    <%= Html.CheckBox("acceptCommunityEmail", ViewState["acceptCommunityEmail"])%>
                </td>
            </tr>
            <tr>
                <td>
                    Send Me Promotions:
                </td>
                <td>
                    <%= Html.CheckBox("acceptAdvertisingEmail", ViewState["acceptAdvertisingEmail"])%>
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td>
                    <%--<input type="submit" value="Update" />--%>
                    <%= Html.SubmitButton("submit", "Update") %>
                </td>
            </tr>
        </table>
    </div>
    <%= Html.Validation().ValidatorInitializationScripts() %>
   <%-- </form>--%>
    <% } %>
</asp:Content>
